<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let a = prompt("请输入一个整数");
        let m = parseInt(prompt("请输入这个整数的进制数"));
        let n = parseInt(prompt("请输入你想要转化的进制数")); 
        /*
         函数功能:将n进制数转化为m进制数
         函数参数：a(用户输入的数字)
                 n(用户想转化几进制数)
                 m(用户输入数字是几进制数)
        
        */
        // let a = 123;
        // let m = 5;
        // let n = 2;
        // let a = 'abc';
        function conver(a, m, n) {

   
          
            let arr = [];
            let arr1 = [];
            // 转化的十进制数
            let sum = 0;
            let re = /^[0-9]+.?[0-9]*$/;
            // console.log(re.test(a));
            // 判断输入值是否为16进制数中的10-15
            if (re.test(a)) {
                a = String(a);
                for (let i = 0; i < a.length; i++) {
                    let t = a[i];
                    arr.unshift(a[i]);
                }
                
                // console.log(typeof a);
            } else {

                a = a;
                let num = "";
                for (let i = 0; i < a.length; i++) {
                    let t = a[i];
                    switch (t) {
                        case 'a':
                        case 'A':
                            t = '10';
                            break;
                        case 'b':
                        case 'B':
                            t = '11';
                            break;
                        case 'c':
                        case 'C':
                            t = '12';
                            break;
                        case 'd':
                        case 'D':
                            t = '13';
                            break;

                        case 'e':
                        case 'E':
                            t = '14';
                            break;
                        case 'f':
                        case 'F':
                            t = '15';
                            break;

                    }
                    arr.unshift(t);

                }       
            }
             
            for (let i = 0; i < arr.length; i++) {
                sum = parseInt(arr[i]) * Math.pow(m, i) + sum;
            }
            // 余数
            let rem;
            while (sum != 0) {
                rem = sum % n;

                if (n == 16) {
                    switch (rem) {
                        case 10:
                            rem = 'A';
                            break;
                        case 11:
                            rem = 'B';
                            break;
                        case 12:
                            rem = 'C';
                            break;
                        case 13:
                            rem = 'D';
                            break;
                        case 14:
                            rem = 'E';
                            break;
                        case 15:
                            rem = 'F';
                            break;

                    }
                }
                arr1.unshift(rem);
                sum = Math.floor(sum / n);
            }
            return arr1.join("");
        }
        console.log(conver(a, m, n));

    </script>
</body>

</html>